<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>校淘</title>
    <link rel="stylesheet" type="text/css" href="css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="css/aui-pull-refresh.css"/>
    <script src="script/jquery.min.js"></script>
    <!--<script type="text/javascript" src="script/car/ionic.bundle.min.js"></script>-->
    <!--<script type="text/javascript" src="script/car/runend.js"></script>-->
    <!--<script src="script/api.js"></script>-->
    <!--<script src="script/aui-scroll.js"></script>-->
    <script src="script/aui-pull-refresh.js"></script>
    <script type="text/javascript">
        //定义全局变量
        var i = 0;
        //金额总和
        var money = 0;
        //计算合计价格
        var cart_money = new Object();
        //全部商品ID
        var cart_id = new Object();
        //备份商品ID，用于全选后去掉全选又再次全选
        var cart_id_copy = new Object();
    </script>
    <style type="text/css">
        .aui-refresh-load {
            position: absolute;
            top: -4.2rem;
        }

        .header_box {
            height: 44px;
            position: fixed !important;
            width: 100%;
            top: 0;
            z-index: 999999;
        }

        .aui-refresh-content {
            top: 2rem;
        }
    </style>
</head>

<body>
<!-- 头部 -->
<div class="header_box" style="background:#53cac3">
    <div class="bar bar-header" style="background:#53cac3">
        <a class="back" href="../index.html" style="padding-top:5px; display:inline-block; padding-left:10px;">
            <i class="aui-iconfont aui-icon-left" style="font-weight:800; color:#fff; font-size:20px;"></i>
        </a>
        <div id="tite" class="h1 title" style=" width: 72%; margin: 0 auto; ">购物车</div>
        <a class="rig_shai" id="rem_s" href="javascript:void(0)"
           style="margin-right: 2%;position: absolute; top: 5px; right: 3%;">
            <i class="aui-iconfont aui-icon-edit" style="font-weight:800; color:#fff; font-size:20px;"></i>
        </a>
    </div>
</div>
<!-- <p id="height" style="position:absolute;top:50%;z-index:9;left:50%;font-size:18px;">高度：</p> -->
<div class="aui-refresh-content">
    <div class="aui-content">
        <div id="demo">
            <form method="post" name="cart_form" target="_self" class="swiper-container" id="cart_form" action="">
                <div class="commodity_list_box aui-card-list">
                    <div class="cart_top">
                        <span>商品清单</span>
                        <div class="clear"></div>
                    </div>
                    <!--商品列表-->
                    <div id="shoplist">
                    </div>
                    <div style="height: 50px;"></div>
                    <!-- 商品列表 end -->
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 全选合计 -->
<div class="settle_box">
    <dl class="all_check select">
        <dt>
            <span id="all_pitch_on" onclick="allChoose()"></span>
            <em>全选</em>
        </dt>
    </dl>
    <dl class="total_amount">
        <dt>
            合计：
            <p id="total_price">
                ¥<b>0</b>
            </p>
        </dt>
        <dd>不含运费</dd>
    </dl>
    <input type="hidden" name="gcs" id="gcs"/>
    <a class="settle_btn" href="javascript:void(0);" id="confirm_cart">去结算</a>
    <a class="settle_btn" href="javascript:void(0);" id="confirm_cart1" onclick="big_cart_remove()">删除</a>
</div>
<!-- 全选 -->
<script>
    var shopMarket = [{
        shopName: "app产品专营店1",
        isFreeSend: false,
        shopList: [{
            id: "1",
            name: "新疆苹果",
            note: "50斤",
            price: 10.00,
            count: 1,
            isSelect: false
        }
        ]
    }, {
        shopName: "app产品专营店2",
        isFreeSend: false,
        shopList: [{
            id: "3",
            name: "新疆苹果",
            note: "50斤",
            price: 30.00,
            count: 1,
            isSelect: false
        }
        ]
    }];

    var result = Model.shopcart.findAllShopcartItemByUserid({
        id: '',
        pageSize: 10,
        page: 1
    })
    showList();

    //显示
    function showList() {
        calculate();
        isAllchoose();
        var lhtml = "";
        for (var i = 0; i < shopMarket.length; i++) {
            lhtml += '<div class="commodity_box">'
            lhtml += '<div class="commodity_list">'
            lhtml += '<div class="tite_tim select">'
            lhtml += '<em aem="1" cart_id="84"></em>'
            lhtml += '<span>' + shopMarket[i].shopName + '</span>'
            lhtml += ' <div class="clear"></div>'
            lhtml += '</div>'
            lhtml += '<ul class="commodity_list_term">'
            lhtml += '<li class="select">'
            if (shopMarket[i].shopList[0].isSelect) {
                lhtml += ' <em onclick="choose(' + shopMarket[i].shopList[0].id + ')" aem="0" cart_id="84" class="pitch_on"></em>'
            } else {
                lhtml += ' <em aem="0" onclick="choose(' + shopMarket[i].shopList[0].id + ')" cart_id="84"></em>'
            }
            lhtml += ' <img src="image/sp1.jpg" />'
            lhtml += ' <div class="div_center">'
            lhtml += ' <h4>' + shopMarket[i].shopList[0].name + '</h4>'
            lhtml += ' <span>' + shopMarket[i].shopList[0].note + '</span>'
            lhtml += '<p class="now_value">'
            lhtml += '<i>￥</i>'
            lhtml += '<b class="qu_su">' + shopMarket[i].shopList[0].price + '</b>'
            lhtml += '</p>'
            lhtml += '</div>'
            lhtml += ' <div class="div_right">'
            lhtml += '<i onclick="reducew(' + shopMarket[i].shopList[0].id + ')">-</i>'
            lhtml += '<span class="zi">' + shopMarket[i].shopList[0].count + '</span>'
            lhtml += '<input type="hidden" value="84">'
            lhtml += '<i onclick="plusw(' + shopMarket[i].shopList[0].id + ')">+</i>'
            lhtml += '</div>'
            lhtml += '</li>'
            lhtml += '</ul>'
            lhtml += ' </div>'
            lhtml += '</div>'
        }
        $("#shoplist").empty().append(lhtml);

    }

    //计算价格
    function calculate() {
        var count = 0;
        for (var i = 0; i < shopMarket.length; i++) {
            for (var j = 0; j < shopMarket[i].shopList.length; j++) {
                if (shopMarket[i].shopList[0].isSelect) {
                    var shopP = shopMarket[i].shopList[0].count * shopMarket[i].shopList[0].price;
                    count += shopP;
                }
            }
        }
        $("#total_price b").text(count)

    }

    //减
    function reducew(id) {
        for (var i = 0; i < shopMarket.length; i++) {
            for (var j = 0; j < shopMarket[i].shopList.length; j++) {
                if (id == shopMarket[i].shopList[0].id && shopMarket[i].shopList[0].count > 1) {
                    shopMarket[i].shopList[0].count--;

                }
            }
        }
        showList();
    }

    //加
    function plusw(id) {
        for (var i = 0; i < shopMarket.length; i++) {
            for (var j = 0; j < shopMarket[i].shopList.length; j++) {
                if (id == shopMarket[i].shopList[0].id) {
                    shopMarket[i].shopList[0].count++;

                }
            }
        }
        showList();
    }

    //单选
    function choose(id) {
        for (var i = 0; i < shopMarket.length; i++) {
            for (var j = 0; j < shopMarket[i].shopList.length; j++) {
                if (id == shopMarket[i].shopList[0].id) {
                    shopMarket[i].shopList[0].isSelect = !shopMarket[i].shopList[0].isSelect;
                }
            }
        }
        isAllchoose();
        showList();
    }

    //判断是否全选
    function isAllchoose() {
        var isAllSec = true;
        for (var i = 0; i < shopMarket.length; i++) {
            for (var j = 0; j < shopMarket[i].shopList.length; j++) {
                if (!shopMarket[i].shopList[0].isSelect) {
                    isAllSec = false;
                }
            }
        }
        if (isAllSec) {
            $("#all_pitch_on").addClass("pitch_on")
        } else {
            $("#all_pitch_on").removeClass("pitch_on")
        }
        return isAllSec;
    }


    //全选
    function allChoose() {

        if (isAllchoose()) {
            $("#all_pitch_on").removeClass("pitch_on")
            for (var i = 0; i < shopMarket.length; i++) {
                for (var j = 0; j < shopMarket[i].shopList.length; j++) {

                    shopMarket[i].shopList[0].isSelect = false;

                }
            }
        } else {
            $("#all_pitch_on").addClass("pitch_on")
            for (var i = 0; i < shopMarket.length; i++) {
                for (var j = 0; j < shopMarket[i].shopList.length; j++) {

                    shopMarket[i].shopList[0].isSelect = true;

                }
            }
        }
        showList();
    }

    var pullRefresh = new auiPullToRefresh({
        container: document.querySelector('.aui-refresh-content'),
        triggerDistance: 100
    }, function (ret) {
        if (ret.status == "success") {
            setTimeout(function () {
                console.log('刷新')
                var n = shopMarket.length + 1;

                var wrap = document.getElementById("demo")
                var shop = {
                    shopName: "app产品专营店" + n,
                    isFreeSend: false,
                    shopList: [{
                        id: (n - 1) * 2 + 1,
                        name: "新疆苹果",
                        note: "50斤",
                        price: 30.00,
                        count: 1,
                        isSelect: false
                    },
                        {
                            id: (n - 1) * 2 + 2,
                            name: "新疆苹果",
                            note: "50斤",
                            price: 40.00,
                            count: 1,
                            isSelect: false
                        }
                    ]
                };
                var arr = new Array();
                arr = shopMarket;

                arr.push(shop);
                showList();
                pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
            }, 1500)
        }
    })
</script>

<!-- 刷新 -->

<script src="../js/lib/jquery-1.8.3.min.js"></script>
<script src="../js/lib/weui.min.js"></script>
<script src="../js/Common.js"></script>
<script src="../js/Model.js"></script>
<script src="../js/views/shop_detail.js"></script>
</body>

</html>